<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="<s:url value="/js/protocol.js"/>"></script>

<s:form id="formEdit" cssClass="tableEdit" >

    <s:if test="%{protocol.id != null && protocol.id != ''}">
    <tr>
        <th colspan="2" class="tableTitle">
            <h5>General Information</h5>
        </th>
    </tr>
    </s:if>
    <s:else>
        <tr>
            <th colspan="4" class="tableTitle">
                <h5>New Protocol</h5>
            </th>
        </tr>
    </s:else>

    <s:textfield label="Protocol ID" name="protocol.id" value="%{protocol.id}" id="protocolId"/>
    <s:textfield label="Protocol Title" name="protocol.title" value="%{protocol.title}"/>
    <s:textfield label="Protocol Name" name="protocol.name" value="%{protocol.name}"/>
    <s:select label="Inhouse" name="protocol.inhouse" id="inhouse"  value="%{protocol.inhouse}"
              list="#{'YES':'YES', 'NO':'NO'}"/>
    <%--<s:textfield label="Disease" name="protocol.disease" value="%{protocol.disease}"/>--%>
    <s:select label="Chronic?" name="protocol.chronic" id="chronic"  value="%{protocol.chronic}"
              list="#{'YES':'YES', 'NO':'NO'}"/>
    <s:doubleselect
            id="areas"
            list="languageMap.keySet()"
            headerKey="-1" headerValue="Choose an Area"
            listKey="id"
            listValue="name"
            label="Therapeutic Area"
            name="protocol.therapeuticArea.id"
            doubleId="specialities"
            doubleHeaderKey="-1" doubleHeaderValue="Choose Specialty"
            doubleListKey="id"
            doubleListValue="name"
            doubleName="protocol.speciality.id"
            doubleList="languageMap.get(top)"/>

    <s:select label="Countries" name="chosenCountries" id="countries" multiple="true"
              headerKey="-1" headerValue="Choose Countries"
              list="countries"
              listKey="id"
              listValue="country"
              value="%{chosenCountries}"/>

    <s:if test="%{protocol == null || protocol.id == null || protocol.drogas.isEmpty()}">
        <tr id="drug">
            <td><s:label value="Drug Name:" theme="simple"/></td>
            <td><s:select name="protocol.drogas[0].id"
                          theme="simple" cssClass="required_group"
                          list="drogas" listKey="id" listValue="drugName"/>
            </td>
            <td><a onclick="deleteRow(this)"><img src="<s:url value="/images/delete2.png"/>" alt="Delete"></a></td>
        </tr>
    </s:if>
    <s:else>
        <s:iterator value="%{protocol.drogas}"  status="stat">
            <tr id="drug">
                <td><s:label value="Drug Name:" theme="simple"/></td>
                <td><s:select name="protocol.drogas[%{#stat.index}].id" value="%{protocol.drogas[#stat.index].id}"
                              theme="simple" cssClass="required_group"
                              headerKey="-1" headerValue="Choose a Drug"
                              list="drogas" listKey="id" listValue="drugName"/>
                </td>
                <td><a onclick="deleteRow(this)"><img src="<s:url value="/images/delete2.png"/>" alt="Delete"></a></td>
            </tr>
        </s:iterator>
    </s:else>
    <tr><td colspan="4" style="text-align: right"><a style="text-align: right" onclick="addRow('<s:url action="getDrugs" namespace="/Protocols"/>')"><img src="<s:url value="/images/add2.png"/>" alt="Add Row"></a></td></tr>

    <tr><td colspan="3" style="text-align: center"><s:submit value="Save" theme="simple" id="save" action="save" onclick="validate();beforeSaveProtocol();"/>
    <s:submit value="Clear" theme="simple" id="clear" onclick="$('#formEdit')[0].reset(); return false;"/></td></tr>

    <s:hidden value="%{llamada}" name="llamada"/>
</s:form>

<script type="text/javascript">
    $('#generalInformation').css({"color":"#EE5102","fontWeight":"bold"});
    $('#new').css({"color":"#EE5102","fontWeight":"bold"});
</script>
<s:if test="%{protocol != null && protocol.id != null && !protocol.id.isEmpty()}">
    <script type="text/javascript">
        $('#protocolId').attr('disabled', 'disabled');
        $('#clear').remove();
    </script>
</s:if>
